package gui;

import gui.perspective.IntroPerspective;

import org.eclipse.ui.application.IWorkbenchConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import vworld.Client;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	private static final String INITIALPERSPECTIVE_ID = IntroPerspective.ID;

	public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		return new ApplicationWorkbenchWindowAdvisor(configurer);
	}

	public void initialize(IWorkbenchConfigurer configurer) {
		super.initialize(configurer);
		configurer.setSaveAndRestore(true);
	}

	public String getInitialWindowPerspectiveId() {
		return INITIALPERSPECTIVE_ID;
	}

	public boolean preShutdown() {
		Client.CONNECTION_SERVICE.logout(Client.CALL_BACK_REF);

		if (Client.CURRENT_ROOM != null) {
			Client.CONNECTED_USER.avatar.state = false;
			Client.ROOM_SERVICE.notifyRoomOnLoginOrLogout(Client.CALL_BACK_REF,
					Client.CONNECTED_USER, false);
		}

		return true;
	};
}
